const mongoose = require('../common/db');

const mailSchema = new mongoose.Schema({
    sender: { type: String, required: true },
    receiver: { type: String, required: true },
    subject: { type: String, required: true },
    content: { type: String, required: true }
});

mailSchema.statics.findBySender = async function (sender) {
    return await this.find({ sender });
};

mailSchema.statics.findByReceiver = async function (receiver) {
    return await this.find({ receiver });
};
mailSchema.statics.query = async function (conditions) {
    return await this.find(conditions);
};

const Mail = mongoose.model('Mail', mailSchema);

module.exports = Mail;